package com.liliang.utils;


import java.io.*;
import java.util.Properties;

/**
 * 读取文件
 */

public class SerialUtil {


	private static Properties property = new Properties();

	//src/main/resources/serial.properties

	static {
		try (
				InputStream in = SerialUtil.class.getClassLoader().getResourceAsStream("serial.properties");
		) {
			property.load(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String get(String key) {
		return property.getProperty(key);
	}

	public static void set(String key,String Value) throws IOException {
		property.setProperty(key,Value);
		FileWriter fw=new FileWriter("E:\\liliang\\xuexi\\biancheng\\zuoye\\liliang\\procurement\\src\\main\\resources\\serial.properties");
		property.store(fw,"liliang");
		fw.close();
	}

//	public static void setValue(String key, String value){
//		property.setProperty(key, value);
//		//此处获取的路径是target下classes
//
//		//这里的path是项目文件的绝对路径
//		//先获取项目绝对路径：Thread.currentThread().getContextClassLoader().getResource("").getPath();
//		//然后在项目路径后面拼接"properties/sysConfig.properties";
//		// 原注释
//		String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
//		path = path + "data.properties";
//		FileOutputStream fileOutputStream = null;
//		try {
//			fileOutputStream = new FileOutputStream(path);
//			property.store(fileOutputStream, "注释");
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			try {
//				if (null != fileOutputStream){
//					fileOutputStream.close();
//				}
//			} catch (IOException e) {
//				System.out.println("data.properties文件流关闭出现异常");
//			}
//		}
//	}

}
